- name: provision koschei
  hosts: os_control[0]:os_control_stg[0]
  user: root
  gather_facts: False

  vars_files:
    - /srv/web/infra/ansible/vars/global.yml
    - /srv/private/ansible/vars.yml
    - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml
    - /srv/web/infra/ansible/roles/openshift-apps/koschei/vars/main.yml
    - /srv/web/infra/ansible/roles/openshift-apps/koschei/vars/{{ env }}.yml

  roles:
  - role: rabbit/queue
    username: "{{ app }}{{ env_suffix }}"
    queue_name: "{{ app }}{{ env_suffix }}"
    routing_keys: []
    message_ttl: 60000
    sent_topics: ^org\.fedoraproject\.{{ env_short }}\.(koschei|ci)\..*

  - openshift/project

  - role: openshift/keytab
    secret_name: keytab
    key: krb5.keytab
    service: koschei
    host: "koschei-backend01{{ env_suffix }}.iad2.fedoraproject.org"

  - role: openshift/route
    routename: frontend
    host: "koschei{{ env_suffix }}.fedoraproject.org"
    serviceport: web
    servicename: frontend
    annotations:
        haproxy.router.openshift.io/set-forwarded-headers: append

  tasks:
    - name: Apply objects
      include_role: name=openshift/object
      vars:
        template: "{{ item }}.yml"
        objectname: "{{ item }}.yml"
      with_items:
        - imagestream
        - frontend-config
        - backend-config
        - admin-config
        - admin-deployment
        - frontend-deployment
        - frontend-service

    - name: Apply DeploymentConfig
      include_role: name=openshift/object
      vars:
        template: backend-deployment.yml
        objectname: "{{ item.name }}-deployment.yml"
        service: "{{ item.name }}"
        min_cpu: "{{ item.cpu[0] }}"
        max_cpu: "{{ item.cpu[1] }}"
        min_mem: "{{ item.memory[0] }}"
        max_mem: "{{ item.memory[1] }}"
      with_items: "{{ koschei_backend_services }}"
      loop_control:
        label: "{{ item.name }}"

    - name: Apply CronJob
      include_role: name=openshift/object
      vars:
        template: cronjob.yml
        objectname: "{{ item.name }}-cronjob.yml"
        name: "{{ item.name }}"
        schedule: "{{ item.schedule }}"
        command: "{{ item.command }}"
      with_items: "{{ koschei_cron_jobs }}"
      loop_control:
        label: "{{ item.name }}"
